<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of admins
 *
 * @author Maulnick
 */
require_once 'document_entity.php';
class Payment_entity extends Document_entity{
    
    public function load($id){
        // retrieve from database
        $data = $this->get_payment($id);
        $this->set_data($data);
        return $this->get_data();
    }
    
    public function save(){
        // insert to database
        $payment = $this->get_data();
        // 1. insert payment
        $step_1 = $this->db->insert('payment',$payment);
        $this->document_id = $this->get_last_id();
        return $step_1;
    }
    
    private function get_last_id(){
        //get last index payment
        $this->db->select('payment_id');
        $this->db->order_by('payment_id', 'DESC');
        $this->db->limit(1);
        $result = $this->db->get('payment');
        if($result->num_rows==1){
            return $result->row(0)->payment_id;
        }else{
            return false;
        }
    }
    
    private function get_payment($payment_id){
        // get payment
        $this->db->where('payment_id',$payment_id);
        $result = $this->db->get('payment');
        if($result->num_rows==1){
            return $result->row(0);
        }else{
            return false;
        }
    }
    
}